home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: thor.cf.ac.uk!news
- From: ghassempoory@cf.ac.uk (M. Ghassempoory)
- Subject: Re: Small question
- Sender: news@cf.ac.uk (USENET News System)
- Message-ID: <DpLH0F.DzI@cf.ac.uk>
- Date: Tue, 9 Apr 1996 12:21:51 GMT
- X-Nntp-Posting-Host: giap.elsy.cf.ac.uk
- Content-Type: Text/Plain; charset=US-ASCII
- References: <31674eeb.132847918@vixa.voyager.net>
- Mime-Version: 1.0
- Organization: ENGIN - UWCC
- X-Newsreader: WinVN 0.99.7
-
- In article <31674eeb.132847918@vixa.voyager.net>, sence@ava.taby.se says...
- >
- >If I have 2 cpp files and i use the same global variable that i define
- >in some file that both cpp-files includes. How do I tell the compiler
- >that the variable is the same and that it shouldn't make space 2
- >times?
- >
- >
- >
- > // bjorn@ava.taby.se
- > // http://www.ava.taby.se/www/sence
-
-
- Most C++/C compilers do not mind this and are clever enough
- to link with only one reference to this global variable. The
- proper way of doing it is to define the variable in the include
- file like this:
-
- extern int globalVar;
-
-
- and then in one of your cpp files which include this do the following
- at the top of the module after includes:
-
- int globalVar = 5;
-
-